package fields;

import java.applet.Applet;
import java.awt.*;

/**
 * @author Vassiliy Kudryashov
 */
public class AppletStarter extends Applet {
    Graphics bufferGraphics;
    Image offscreen;
    Dimension dim;
    private Painter painter;

    public AppletStarter() {
        setLayout(new GridLayout(1, 1));
        painter = new Painter();
        add(painter);
    }

    @Override
    public void init() {
        dim = getSize();
        setBackground(Color.black);
        offscreen = createImage(dim.width, dim.height);
        bufferGraphics = offscreen.getGraphics();
    }

    @Override
    public void paint(Graphics g) {
        bufferGraphics.clearRect(0, 0, dim.width, dim.height);
        painter.paint(bufferGraphics);
        g.drawImage(offscreen, 0, 0, this);
    }

    public void update(Graphics g) {
        paint(g);
    }
}
